//一般直接写在一个js文件中
layui.use(['element','form'],function () {
    var form = layui.form;
    //表单验证
    form.verify({
        selectDistinct: function (value, item) { //value：表单的值、item：表单的DOM对象
            var budid = $("#buildingId").val();
            var floor = $("#floorNo").val();
            var code = $("#code").val();
            var budname = $("#buildingId option:selected").text();
            var flag=false;
            $.ajax({
                url:"/room/selectDistinct",
                dataType:"json",
                async:false,
                type:"post",
                data:{budid:budid,floor:floor,code:code},
                success:function(rs){
                    if(rs.code == 200 ){
                        if ( rs.data!=null) flag=true;
                    }
                }
            });
            if (flag) return budname+"-"+floor+"-"+ code+ '已存在';
        }
    });
    form.on('select(buildingId)', function(data){
        buildingId = data.value;
        if(data.value){
            $.ajax({
                url:"/building/selectBuid",
                data:{buildingId:buildingId},
                dataType:'json',
                success:function(rs){
                    $("#floorNo").empty().append('<option value="">请选择楼层</option>');
                    if(rs.code == 200){
                        for (var i=0;i<rs.data.floors;i++){
                            $("#floorNo").append('<option value="'+ (i+1) +'">'+ (i+1) +'</option>');
                        }
                    }
                    form.render('select'); //刷新select选择框渲染
                }
            });
        }
    });
});